package com.tensquare.qa.dao;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;

import com.tensquare.qa.pojo.Problem;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * 数据访问接口
 * @author Administrator
 */
public interface ProblemDao extends JpaRepository<Problem,String>,JpaSpecificationExecutor<Problem>{

    /**
     * 根据标签id查询最新问答
     */
    @Query(value = "select * from tb_problem a,tb_pl b where a.id=b.problemid and b.labelid=? order by a.replytime desc",nativeQuery = true)
    public List<Problem> getNewProblem(String labelId, Pageable pageable);

    /**
     * 最热回答reply回复数
     */
    @Query(value = "select * from tb_problem a,tb_pl b where a.id=b.problemid and b.labelid=? order by a.reply DESC",nativeQuery = true)
    public Page<Problem> getHotProblem(String labelId, Pageable pageable);

    /**
     * 等待回答
     */
    @Query(value = "select * from tb_problem a,tb_pl b where a.id=b.problemid and b.labelid=? order by a.createtime DESC",nativeQuery = true)
    public Page<Problem> getWaitProblem(String labelId, Pageable pageable);
}
